package tech.pdai.springboot.springtasks.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * 若不指定TaskScheduler,则使用默认的 {@link org.springframework.scheduling.config.ScheduledTaskRegistrar#afterPropertiesSet()},单个线程会进行阻塞
 */
@Configuration
public class SpringTaskConfig {

    @Bean("taskScheduler")
    public TaskScheduler threadPoolTaskScheduler() {
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        threadPoolTaskScheduler.setPoolSize(10);
        threadPoolTaskScheduler.setThreadNamePrefix("local-task-");
        return threadPoolTaskScheduler;
    }
}
